package com.seckill.goods.task.dynamic;

import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration;
import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * @program: seckill-parent
 * @description: 这个是elastic-job的配置文件
 * @author: zhanghz001
 * @create: 2021-06-27 11:24
 **/
// @Configuration
public class ZhzElasticJobConfig {
    @Value("${zk}")
    private String serverlists;
    
    @Value("${namesp}")
    private String namespace;
    
    /**
     * 配置zookeeper的namespace
     */
    @Bean
    public ZookeeperConfiguration zkConfig() {
        return new ZookeeperConfiguration(serverlists, namespace);
    }
    
    /**
     * 向zookeeper注册初始化信息
     *
     * @param zkConfig 初始化信息
     * @return
     */
    @Bean
    public ZookeeperRegistryCenter zookeeperRegistryCenter(ZookeeperConfiguration zkConfig) {
        return new ZookeeperRegistryCenter(zkConfig);
    }
    
    /**
     * 配置监听器实例
     *
     * @return
     */
    @Bean
    public ZhzElasticJobListener jobListener() {
        //初始化要给定超时多少秒重连
        return new ZhzElasticJobListener(100L, 100L);
    }
}
